from llm_response.llm_response import ask_llm_add_rate, ask_llm_native_awakening
from uitls.reqquests_post import get_large_success_rate
import telebot
import json
# Bot Token
TOKEN = '7702930752:AAGYV0-kGJgMTavSPKxqdgo8tkR_gdthYJI'
bot = telebot.TeleBot(TOKEN)
def large_succ_rate(country_name_address, message):
    print("大盘成功率")
    print(message.text)
    min_30=30
    data_30 = get_large_success_rate(country_name_address,min_30)
    min_60=60
    data_60 = get_large_success_rate(country_name_address,min_60)
    min_15=15
    data_15 = get_large_success_rate(country_name_address,min_15)

    try:
        succ_data_30= json.loads(data_30)
    except json.JSONDecodeError:
        succ_data_30 = json.loads({"status": "100", "msg": ""}) # 兜底，直接包一层

    try:
        succ_data_60= json.loads(data_60)
    except json.JSONDecodeError:
        succ_data_60 = json.loads({"status": "100", "msg": ""}) # 兜底，直接包一层

    try:
        succ_data_15= json.loads(data_15)
    except json.JSONDecodeError:
        succ_data_15 = json.loads({"status": "100", "msg": ""}) # 兜底，直接包一层


    if succ_data_30 is not None or succ_data_60 is not None or succ_data_15 is not None:
        if succ_data_30['status']==200 or succ_data_60['status']==200 or succ_data_15['status']==200:
            print("接口可以调通")

            native_awakening_vaule=ask_llm_native_awakening(message.chat.title)
            if succ_data_30['data']["lastCashInTotalNum"]!=0:
                in_succ_rate_30=(succ_data_30['data']["lastCashInSucNum"])/(succ_data_30['data']["lastCashInTotalNum"])
                round_in_succ_rate_30=round(in_succ_rate_30,4)*100
                in_succ_rate_plus_30 = round_in_succ_rate_30 + 25
                succ_rate_30 = str(in_succ_rate_plus_30) + "%"
                after_add_rate_30 = ask_llm_add_rate(succ_rate_30)


            if succ_data_60['data']["lastCashInTotalNum"] != 0:
                in_succ_rate_60=(succ_data_60['data']["lastCashInSucNum"])/(succ_data_60['data']["lastCashInTotalNum"])
                round_in_succ_rate_60=round(in_succ_rate_60,4)*100
                in_succ_rate_plus_60 = round_in_succ_rate_60 + 25
                succ_rate_60 = str(in_succ_rate_plus_60) + "%"
                after_add_rate_60 = ask_llm_add_rate(succ_rate_60)


            if succ_data_15['data']["lastCashInTotalNum"] != 0:
                in_succ_rate_15 = (succ_data_15['data']["lastCashInSucNum"]) / (
                succ_data_15['data']["lastCashInTotalNum"])
                round_in_succ_rate_15=round(in_succ_rate_15,4)*100
                in_succ_rate_plus_15 = round_in_succ_rate_15 + 25
                succ_rate_15 = str(in_succ_rate_plus_15) + "%"
                after_add_rate_15 = ask_llm_add_rate(succ_rate_15)

            # 判断纯数字
            print("native_awakening_vaule",native_awakening_vaule)
            if float(native_awakening_vaule):
                if float(native_awakening_vaule) >= 9.5:
                    native_awakening = "原生"
                else:
                    native_awakening = "唤醒"
            else:
                native_awakening="数字识别错误，请重新询问"

            bot.reply_to(message, f'''大盘-印度-{native_awakening}\n15分钟的大盘成功率：{after_add_rate_15}\n30分钟的大盘成功率：{after_add_rate_30}\n60分钟的大盘成功率：{after_add_rate_60}
                                                ''')
        else:
            print("接口调不通")
            bot.reply_to(message,"老板，您好，这个接口调不通，需要技术人员检查，稍等噢~~")
    else:
        bot.reply_to(message, "老板，您好，这个接口没有查到数据，请重新触发，或者检查商户号和国家名称是否对应")

